<template>
  <el-form :inline="true" :model="queryParam" class="demo-form-inline">
    <el-form-item label="用户名">
      <el-input v-model="queryParam.userName" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="用户昵称">
      <el-input v-model="queryParam.nickName" placeholder="用户昵称"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">查询</el-button>
    </el-form-item>
  </el-form>
  <div class="flex">

    <el-button type="primary" :icon="Plus" v-hasRole="['admin']" @click="dialogVisable=true"/>
    <el-button type="primary" :icon="Share"/>
    <el-button type="primary" :icon="Delete"/>
    <el-button type="primary" :icon="Search">Search</el-button>
    <el-button type="primary">
      Upload
      <el-icon class="el-icon--right">
        <Upload/>
      </el-icon>
    </el-button>
  </div>
  <el-table ref="tableRef" row-key="userName" :data="tableData" style="width: 100%">
    <el-table-column prop="userName" label="用户名"/>
    <el-table-column prop="nickName" label="昵称"/>
    <el-table-column prop="email" label="邮箱"/>
  </el-table>
  <el-pagination
      background
      layout="prev, pager, next" @current-change="changePage"
      :total="total" :page-size="queryParam.size">
  </el-pagination>

  <el-dialog v-model="dialogVisable" title="Warning" width="30%" center>
    <span
    >It should be noted that the content will not be aligned in center by
      default</span
    >
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisable = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisable = false"
        >Confirm</el-button
        >
      </span>
    </template>
  </el-dialog>

</template>

<script setup>
import {ref} from 'vue'
import {ElTable} from 'element-plus'
import {listUser} from "@/api/user";
import {onMounted} from 'vue'
import {Delete, Search, Share, Upload, Plus} from '@element-plus/icons-vue'

const queryParam = ref({
  size: 2,
  page: 0,
  userName: '',
  nickName: ''
})
let dialogVisable = ref(false);
const tableData = ref([])
const total = ref(0);


const getList = function () {
  listUser(queryParam.value).then(res => {
    tableData.value = res.data.content;
    total.value = res.data.totalElements;
    queryParam.value.size = res.data.size;
  })
}

onMounted(() => {
  getList()
})

const changePage = async function (current) {
  queryParam.value.page = current - 1;
  getList()
}

const onSubmit = function () {
  getList();
};


</script>


<style>

</style>